#include "qbaseitemdelegate.h"

#include <QPainter>
#include <QApplication>

void QBaseItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    QStyleOptionViewItemV3 opt=option;

    QColor c(BACKGROUND_COLOR);

    if(!index.data(ITEM_IS_DARK).toBool())
    {
        if(opt.features & QStyleOptionViewItemV2::Alternate)
        {
            c=c.lighter(112);
        }
    }
    else
    {
        c=opt.palette.color(QPalette::Dark);
        opt.palette.setColor(QPalette::Text,opt.palette.color(QPalette::BrightText));
    }


    painter->fillRect(option.rect,c);
    opt.state &=~ QStyle::State_HasFocus;
    QItemDelegate::paint(painter,opt,index);
    opt.palette.setCurrentColorGroup(QPalette::Active);
    QColor color=static_cast<QRgb>(qApp->style()->styleHint(QStyle::SH_Table_GridLineColor,&opt));
    painter->setPen(color);
    int right=option.rect.right();
    painter->drawLine(right,option.rect.y(),right,option.rect.bottom());
}

QSize QBaseItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    QSize size=QItemDelegate::sizeHint(option,index);
    size.setHeight(24);
    size.rwidth()+=4;
    return size;
}
